#include<iostream>
#include<cstring>
using namespace std;


#define maxm 1024 + 10
#define maxn 32

int picture[maxn][maxn];

// 填充黑色
void draw(char *s, int &p, int x,int y,int w){
    char c = s[p++];
    if(c=='p'){ // 是父母节点
        draw(s,p,x,y+w/2,w/2);
        draw(s,p,x,y,w/2);
        draw(s,p,x+w/2,y,w/2);
        draw(s,p,x+w/2,y+w/2,w/2);
    }
    // 填充黑色
    if(c=='f'){
        for(int i=x;i<x+w;i++){
            for(int j=y;j<y+w;j++){
                picture[i][j] = 1;
            }
        }
    }
}

// 统计黑色像素个数
int statistic(){
    int sum=0;
    for(int i=0;i<maxn;i++){
        for(int j=0;j<maxn;j++){
            sum += picture[i][j];
        }
    }
    return sum;
}

int main(){

    char t1[maxm],t2[maxm];
    int n;
    cin>>n;
    while(n--){
        cin >> t1 >> t2;
        memset(picture,0,sizeof(picture));
        int p=0;
        draw(t1,p,0,0,maxn);
        p=0;
        draw(t2,p,0,0,maxn);

        cout<<"There are "<<statistic()<<" black pixels."<<endl;
    }


    return 0;
}